﻿using Decoration.IRepository;
using Decoration.IService;
using Decoration.Models.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Decoration.Service
{
    public class UserProcedureService : BaseService<UserProcedure>, IUserProcedureService
    {
        private readonly IUserProcedureRepository rep;
        private readonly IProjectInfoRepository projectRep;

        public UserProcedureService(IUserProcedureRepository rep,IProjectInfoRepository projectRep, IBaseQueryRepository brep) : base(rep, brep)
        {
            this.rep = rep;
            this.projectRep = projectRep;
        }

        public bool AddRange(IEnumerable<UserProcedure> userProcedures)
        {
            foreach (var item in userProcedures)
            {
                rep.Add(item);
            }

            var project = projectRep.Get(p => p.Id == userProcedures.First().ProjectId);
            project.CompletedStatus = 1;
            return rep.SaveChanges();
        }
    }
}
